package cn.bdqn.util;

import java.util.Random;
import java.util.regex.Pattern;

public class Constant {
    /**
     * 正则表达式：验证手机号
     */
    public static final String REGEX_MOBILE = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    /**
     * 正则表达式：验证身份证
     */
    public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";
    /**
     * 正则表达式：验证邮箱
     */
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    /**
     * 校验手机号
     *
     * @param phone
     * @return 校验通过返回true，否则返回false
     */
    public static boolean isMobile(String phone) {
        return Pattern.matches(REGEX_MOBILE, phone);
    }

    /**
     * 校验身份证
     *
     * @param idCard
     * @return 校验通过返回true，否则返回false
     */
    public static boolean isIDCard(String idCard) {
        return Pattern.matches(REGEX_ID_CARD, idCard);
    }
    /**
     * 校验邮箱
     *
     * @param email
     * @return 校验通过返回true，否则返回false
     */
    public static boolean isEmail(String email) {
        return Pattern.matches(REGEX_EMAIL, email);
    }

    /**
     * 随机数
     * @param count
     * @return
     */
    public static String randomTool(Integer count){

        Random random = new Random();
        String result="";
        for (int i=0;i<count;i++)
        {
            result+=random.nextInt(10);
        }
        return result;
    }

    /**
     * 图片格式
     * @param fileName
     * @return
     */
    public static boolean ImageForm(String fileName){
        String ext=fileName.substring(fileName.lastIndexOf("."));
        if (ext.matches("^(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$")) {
            return true;
        }else {
            return false;
        }

    }
}
